import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.zip.Inflater;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class WizzardAttack extends JFrame
{
	static DMserver server;
	
	JLabel lblTarget = new JLabel("target"); 
	JTextField txtTarget = new JTextField();
	
	JLabel lblRange = new JLabel("range"); 
	JTextField txtRange = new JTextField();
	
	public WizzardAttack(final DMserver server)
	{
		setTitle("wizzard attack");
		setSize(500,140);
		setVisible(true);
		
		GridLayout layout = new GridLayout(3,2);
		
		JButton btnAttack = new JButton("attack");
		
		setLayout(layout);
		
		add(lblTarget);
		add(txtTarget);
		
		add(lblRange);
		add(txtRange);
		
		add(btnAttack);
		
		
		btnAttack.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				try 
				{
				
					int range = Integer.parseInt(txtRange.getText());
					if (range < 0) { range = 0;}
					int toHit = GameEngine.roll(100) + (10 - range/3);
					int damage = GameEngine.roll(2, 5) + (1 - range/5);
					int DOTdam = GameEngine.roll(2, 3);
					if(damage < 0){ damage = 0;}
					if(!txtTarget.getText().equals(""))
					{
						int target = Integer.parseInt(txtTarget.getText());
						server.sendDOTAttack(toHit, damage, DOTdam, 1, target);
					}
					else
					{
						System.out.println("attack:" + toHit + " damage:" + damage + " DOT:" + DOTdam);
						server.writeMessage("attack:" + toHit + " damage:" + damage + " DOT:" + DOTdam);
					}
				}
				catch (Exception e) {e.printStackTrace();}
			}	
		});
	}
}
